package homework;

import java.util.concurrent.CountDownLatch;

public class demo14 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);

        for (int i = 0; i < 5; i++) {
            int id = i;
            Thread t = new Thread(() -> {
                try {
                    Thread.sleep(1000);                    
                } catch (Exception e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
                System.out.println("线程" + id + "执行完毕");
                countDownLatch.countDown();
            });
            t.start();
        }

        countDownLatch.await();
        System.out.println("所有任务都执行完毕");
    }
}
